package com.example.leetcode.search;

import com.example.leetcode.search.comon.GuessGame;

class Solution374 extends GuessGame {
    public int guessNumber(int n) {
        int left = 1;
        int right = n;
        while (left <= right) {
            if (left == right) {
                if (guess(left) == 0) {
                    return left;
                } else {
                    break;
                }
            }
            int mid = left + (right - left) / 2;
            int guessResult = guess(mid);
            if (guessResult == 0) {
                return mid;
            } else if (guessResult == -1) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }
}

public class leetcode374 {
    public static void main(String[] args) {
        Solution374 solution374 = new Solution374();
        test374(solution374, 10, 6);
        test374(solution374, 1, 1);
        test374(solution374, 2, 1);
        test374(solution374, 2, 2);
    }

    private static void test374(Solution374 solution374, int num, int pick) {
        solution374.setPick(pick);
        System.out.println(solution374.guessNumber(num));
    }
}
